package cn.tedu.luban.account.main.rpc;

import cn.tedu.luban.account.api.AccountApi;
import cn.tedu.luban.account.main.service.AccountService;
import cn.tedu.luban.account.protocol.dto.AccountDTO;
import cn.tedu.luban.account.protocol.param.AccountCreateParam;
import cn.tedu.luban.account.protocol.param.AccountPayParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AccountApiImpl implements AccountApi {
    @Autowired
    private AccountService accountService;
    @Override
    public Long createAccount(AccountCreateParam accountCreateParam) {
        Long result=0l;
        try{
            //1. 调用业务层 创建账户,成功创建业务层返回1 失败返回0 或者抛异常
            result=accountService.createAccount(accountCreateParam);
        }catch (Throwable e){
            log.error("账号参数:{},新增创建失败",accountCreateParam,e);
        }
        return result;
    }
    @Override
    public AccountDTO getAccount(Long userId) {
        AccountDTO accountDTO=null;
        try {
            accountDTO=accountService.getAccount(userId);
        }catch (Throwable e){
            log.error("获取账号信息失败,用户id:{}",userId,e);
        }
        return accountDTO;
    }

    @Override
    public Long mockPayment(AccountPayParam param) {
        //TODO
        return null;
    }
}
